# -*- coding: utf-8 -*-
"""
@Time    : 2025/2/12 18:48 
@Author  : ZhangShenao 
@File    : 3.image_recognition.py 
@Desc    : 图片识别
"""

import os

import dotenv
from openai import OpenAI

# 创建OpenAI客户端
dotenv.load_dotenv()
client = OpenAI(base_url=os.getenv("OPENAI_API_BASE"))

# 调用ChatCompletion API,获取图片识别结果
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "给我讲讲这张图片的内容"},
                {
                    "type": "image_url",  # 指定消息类型为图片url
                    "image_url": {  # 指定图片url
                        "url": "https://p7.itc.cn/q_70/images03/20220805/7a369d8407144b11bfd598091095c959.jpeg",
                    }
                },
            ],
        }
    ],
    max_tokens=50,  # 指定最大token数量
)

# 获取结果
print(response.choices[0].message.content)
